import React, { Component } from 'react'
import { Router, Route, Switch } from 'react-router-dom'
// 导入封装的鉴权路由组件
import AuthRoute from 'components/AuthRoute'
import history from 'utils/history'

// import Layout from './pages/Layout'
// import Login from './pages/Login'
// import Test from 'pages/Test'

//路由懒加载
import Loading from './components/Loading'
const Login = React.lazy(() => import('pages/Login'))
const Layout = React.lazy(() => import('pages/Layout'))
const Test = React.lazy(() => import('pages/Test'))

export default class App extends Component {
  render() {
    return (
      <Router history={history}>
        <React.Suspense fallback={<Loading />}>
          <Switch>
            {/* 按书写顺序从上往下匹配，需先匹配登录页 */}
            <Route path="/login" component={Login} />
            <Route path="/Test" component={Test} />
            {/* 嵌套路由的父路由不能写精确匹配 */}
            {/* <Route path='/' component={Layout} /> */}
            {/* Route 组件进阶写法： render 函数渲染组件写法  */}
            {/* 导入鉴权路由组件 - 封装成组件以后项目都可复用 */}
            <AuthRoute path="/" component={Layout} aa={11} bb={22} />
          </Switch>
        </React.Suspense>
      </Router>
    )
  }
}
